package com.lxh.lxhcrm.model.pojos;

import javax.persistence.*;
import java.util.Objects;

/**
 * @author ：鞠玮
 * 开发团队 ：lxh
 * 开发时间 ：2020/3/2 15:15
 * 类的名称 ：ProductList
 * 类的描述 ：合同相关的商品集合，也为合同与商品的中间表
 */
@Entity
@Table(name = "product_list", schema = "lxh_crm")
public class ProductList {
    private int listId;
    private Integer proCount;
    private Double discount;

    /** 商品 */
    private ProDetail proDetail;
    /** 合同 */
    private Contract contract;


    @Id
    @Column(name = "list_id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getListId() {
        return listId;
    }

    public void setListId(int listId) {
        this.listId = listId;
    }

    @ManyToOne
    @JoinColumn(name = "pro_detail_id")
    public ProDetail getProDetail() {
        return proDetail;
    }

    public void setProDetail(ProDetail proDetail) {
        this.proDetail = proDetail;
    }

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "contract_id")
    public Contract getContract() {
        return contract;
    }

    public void setContract(Contract contract) {
        this.contract = contract;
    }

    @Basic
    @Column(name = "pro_count", nullable = true)
    public Integer getProCount() {
        return proCount;
    }

    public void setProCount(Integer proCount) {
        this.proCount = proCount;
    }

    @Basic
    @Column(name = "discount", nullable = true, precision = 0)
    public Double getDiscount() {
        return discount;
    }

    public void setDiscount(Double discount) {
        this.discount = discount;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ProductList that = (ProductList) o;
        return listId == that.listId &&
                Objects.equals(proCount, that.proCount) &&
                Objects.equals(discount, that.discount) &&
                Objects.equals(proDetail, that.proDetail) &&
                Objects.equals(contract, that.contract);
    }

    @Override
    public int hashCode() {
        return Objects.hash(listId, proCount, discount, proDetail, contract);
    }

    @Override
    public String toString() {
        return "ProductList{" +
                "listId=" + listId +
                ", proCount=" + proCount +
                ", discount=" + discount +
                ", proDetail=" + proDetail +
                ", contract=" + contract +
                '}';
    }
}
